    var folder = document.getElementById('picfolder').value;
    var host = "";
    var policyBase64 = "";
    var accessid = "";
    var signature = "";
    var callbackbody = "";
    var key = "";
    var g_object_name = '';
    var g_object_name_type = '';
    var suffix = ""; //文件后缀名
    var ajax_return = "";
    var $loading;
    var $selectfile = $('.selectfile')
    //得到后缀名
    function get_suffix(filename) {
      pos = filename.lastIndexOf('.');
      if (pos != -1) {
        suffix = filename.substring(pos);
      }
      return suffix;
    }

    //返回字符串　
    function random_string(len) {
      len = len || 32;
      var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
      var maxPos = chars.length;
      var pwd = '';
      for (i = 0; i < len; i++) {
        pwd += chars.charAt(Math.floor(Math.random() * maxPos));
      }
      return pwd;
    }

    function check_object_radio() {
      var tt = document.getElementsByName('myradio');
      g_object_name_type = tt[0].value;
    }


    function calculate_object_name(filename) {
      if (g_object_name_type == 'local_name') {
        g_object_name += "${filename}";
      } else if (g_object_name_type == 'random_name') {
        suffix = get_suffix(filename);
        g_object_name = key + random_string(10) + suffix;
      }
      return '';
    }

    //得到上传文件名
    function get_uploaded_object_name(filename) {
      if (g_object_name_type == 'local_name') {
        tmp_name = g_object_name;
        tmp_name = tmp_name.replace("${filename}", filename);
        return tmp_name;
      } else if (g_object_name_type == 'random_name') {
        return g_object_name;
      }
    }

    function send_request() {
      var xmlhttp = null;
      if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }

      if (xmlhttp !== null) {
        serverUrl = '/mobile/ossget/index?folder=' + folder;
        xmlhttp.open("GET", serverUrl, false);
        xmlhttp.send(null);
        return JSON.parse(xmlhttp.responseText);
      } else {
        alert("您的浏览器不支持xmlHttp，请更换浏览器");
      }


    }

    //设置上传参数 并 上传文件
    function set_upload_param(up, filename, ret) {
      ajax_return = send_request();
      host = ajax_return.host;
      policyBase64 = ajax_return.policy;
      accessid = ajax_return.accessid;
      signature = ajax_return.signature;
      callbackbody = ajax_return.callback;
      key = ajax_return.dir;

      g_object_name = key;
      if (filename !== '') {
        check_object_radio();
        suffix = get_suffix(filename);
        calculate_object_name(filename);
      }

      var new_multipart_params = {
        'key': g_object_name,
        'policy': policyBase64,
        'OSSAccessKeyId': accessid,
        'success_action_status': '200',
        'callback': callbackbody,
        'signature': signature,
      };

      up.setOption({ //设置配置
        'url': host,
        'multipart_params': new_multipart_params
      });

      up.start(); //开始上传队列中的文件
    }

    function upSuccess(src, name, imgsrc, type, id) {
      var field = {};
      field[name] = imgsrc;
      $.ajax({
        type: "post",
        url: src,
        data: field,
        dataType: "json",
        success: function(result) {
          if (result.code == -1) {
            weui.topTips("登录超时,请重新登录");
            $('.bodybg,#onlybtn').off('click').on('click', function(event) {
              event.preventDefault();
              location.href = '/mobile/login';
            });
          } else if (result.code == '1') {
            weui.toast('图片上传并保存成功', 2000);
          } else {
            weui.topTips(result.msg);
          }
          return;
        }
      });
    }

    $selectfile.each(function(index, item) {
      var id = $(item).attr('id'),
        pic = $(item).find('.pic'),
        url = $(item).data('url'),
        name = $(item).data('name');

      var uploaded = [],
        uploadItem = {
          name: '',
          url: '',
          src: ''
        }; //记录本次已上传过的照片
      var uploader = new plupload.Uploader({
        browse_button: id,
        url: 'http://oss.aliyuncs.com',
        flash_swf_url: '/res/mobile/js/plupload/Moxie.swf',
        silverlight_xap_url: '/res/mobile/js/plupload/Moxie.xap',
        filters: {
          mime_types: [
            { title: "Image files", extensions: "image/jpg,image/jpeg,jpg,jpeg,gif,png,bmp" }
          ],
          max_file_size: '8mb', //最大只能上传8mb的文件
          prevent_duplicates: true //不允许选取重复文件
        },
        init: {
          init: function() {
            console.log('上传初始化完成');
          },
          FilesAdded: function(up, files) { //当文件添加到上传队列后触发
            console.log('文件被添加当上传队列');
            set_upload_param(up, files[0].name);
            uploadItem = $.extend({}, uploadItem, {
              name: files[0].name
            })
          },
          BeforeUpload: function(up, file) {
            $loading = weui.loading('正在上传,请稍候');
          },
          FileUploaded: function(up, file, info) {
            $loading.hide();
            if (info.status == 200) {
              uploadItem = $.extend({}, uploadItem, {
                src: get_uploaded_object_name(file.name),
                url: IMG_URL + get_uploaded_object_name(file.name)
              })
              uploaded.push(uploadItem)
              pic.attr("src", IMG_URL + get_uploaded_object_name(file.name))
              pic.attr("data-src", get_uploaded_object_name(file.name))
              if (url) {
                upSuccess(url, name, get_uploaded_object_name(file.name));
              }
            } else {
              console.error('FileUploaded:' + info.response);
              weui.topTips(info.response);
            }

          },
          Error: function(up, err) {
            $loading = weui.loading();
            if (err.code == -600) {
              $loading.hide();
              weui.topTips('你选择的上传文件过大，请上传小于8M的图片')
            } else if (err.code == -601) {
              $loading.hide();
              weui.topTips('只能上传格式为jpg/gif/png/bmp图片文件')
            } else if (err.code == -602) {
              $loading.hide();
              // weui.topTips('这个图片你已经上传过啦！')
              pic.attr("src", uploaded.find(function(item) {
                return item.name == err.file.name
              }).url)
              pic.attr("data-src", uploaded.find(function(item) {
                return item.name == err.file.name
              }).src)
            } else {
              $loading.hide();
              weui.topTips('服务器打了个盹儿，文件飞走啦，请重试！')
            }
          }
        }
      });
      uploader.init();
    })
